﻿using Loaf.Beans;
using Loaf.ViewModels;
using Loaf.Views;
using Prism.DryIoc;
using Prism.Ioc;
using System.Text;
using System.Windows;

namespace Loaf
{
    public partial class App : PrismApplication
    {
        protected override Window CreateShell()
        {
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

            Container.Resolve<Context>().ReadContext();

            _ = Task.Run(async () =>
            {
                while (true)
                {
                    Container.Resolve<Context>().WriteContext();
                    await Task.Delay(TimeSpan.FromMinutes(5));
                }
            });

            return Container.Resolve<MainWindow>();
        }

        protected override void RegisterTypes(IContainerRegistry containerRegistry)
        {
            containerRegistry.RegisterSingleton<Context>();

            containerRegistry.RegisterForNavigation<MainWindow, MainWindowModel>();
            containerRegistry.RegisterForNavigation<HomeView, HomeViewModel>();
            containerRegistry.RegisterForNavigation<BookshelfView, BookshelfViewModel>();
            containerRegistry.RegisterForNavigation<SettingView, SettingViewModel>();
            containerRegistry.RegisterForNavigation<ReaderWindow, ReaderWindowModel>();
        }
    }

}
